#pragma once

#include <gofcl_usbfs_grstat_dev.h>

typedef enum {
	USBFS_GRSTAT_DEV_DATA0 = 0,
	USBFS_GRSTAT_DEV_DATA1 = 2,
} usbfs_grstat_dev_dpid_e;

typedef enum {
	USBFS_GRSTAT_DEV_NAK = 1,
	USBFS_GRSTAT_DEV_OUT = 2,
	USBFS_GRSTAT_DEV_OUT_FINISH = 3,
	USBFS_GRSTAT_DEV_SETUP_FINISH = 4,
	USBFS_GRSTAT_DEV_SETUP = 6,
} usbfs_grstat_dev_rpckst_e;

typedef struct {
	u32_s ep_no : 4;
	u32_s size : 11;
	usbfs_grstat_dev_dpid_e pid : 2;
	usbfs_grstat_dev_rpckst_e stat : 4;
	u32_s : 11;
} usbfs_grstat_dev_expl_s;

_Static_assert(sizeof(usbfs_grstat_dev_expl_s) == 4,
	       "Struct usbfs_grstat_dev_expl_s defined error!");

static inline usbfs_grstat_dev_expl_s usbfs_get_recv_stat(void) {
	union {
		usbfs_grstat_dev_expl_s e;
		usbfs_grstat_dev_s g;
	} eg = {
		.g = usbfs_rreg_grstatr_dev_s(),
	};
	return eg.e;
}

static inline usbfs_grstat_dev_expl_s usbfs_pop_recv_stat(void) {
	union {
		usbfs_grstat_dev_expl_s e;
		usbfs_grstat_dev_s g;
	} eg = {
		.g = usbfs_rreg_grstatp_dev_s(),
	};
	return eg.e;
}
